<%--
  Created by IntelliJ IDEA.
  User: 王永超
  Date: 2021/7/15
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <script src="jquery-3.6.0.min.js"></script>
</head>
<body>
    修改密码<br/>
    当前密码：<input type="password" id="sourcePsw"><img id="img1" src="upload/util/error.jpg"><br/>
    修改后的密码<input type="password" id="updatePsw"><img id="img2" src="upload/util/error.jpg"><br/>
    <input type="submit" value="提交" onclick="Get()">
    <script>
        var flag = 0;
        function Get(){
            var sourcePsw = $("#sourcePsw").val();
            var updatePsw = $("#updatePsw").val();
            if(flag==2){
                $.ajax({
                    url :"${pageContext.request.contextPath}/main.do?cmd=updatePsw"
                    ,data : {"sourcePsw":sourcePsw,"updatePsw":updatePsw}
                    ,success:function (result) {
                        console.log("result"+result);
                        if(result=="ok"){
                            alert("修改成功！");
                            window.location = "login.jsp";
                        }else{
                            alert("修改失败！");
                        }
                    }
                });
            }else{
                alert("请填写以下内容");
            }


        }
        /*当第一个输入框被聚焦时*/
        $("#sourcePsw").blur(function (){
            var sourcePsw = $("#sourcePsw").val();
            var updatePsw = $("#updatePsw").val();
            console.log("sourcePsw失去焦点");
            console.log("sourcePsw为"+sourcePsw);
            $.ajax({
                url:"${pageContext.request.contextPath}/main.do?cmd=focus",
                data: {"sourcePsw":sourcePsw},
                success:function (data){
                    console.log("data:"+data);
                    if(data=="ok"){
                        flag++;
                        $("#img1").attr("src","upload/util/ok.jpg");
                    }else if(data=="error"){
                        $("#img1").attr("src","upload/util/error.jpg");
                    }
                }
            });
        });

        /*当第一个输入框被聚焦时*/
        $("#updatePsw").blur(function (){
            var sourcePsw = $("#sourcePsw").val();
            var updatePsw = $("#updatePsw").val();
            console.log("updatePsw被聚焦");
                var updatePsw = $("#updatePsw").val();
                if(updatePsw.length>0){
                    flag++;
                    $("#img2").attr("src","upload/util/ok.jpg");
                }else{
                    $("#img2").attr("src","upload/util/error.jpg");
                }
        });
    </script>
</body>
</html>
